package q;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class GQxQN implements Operation<Q, QxQ> {

    private final int n;
    private final int N;

    private GQxQN(int n) {
        this.n = n;
        N = (int) Math.sqrt(n);
    }

    public static GQxQN GQxQ(int n) {
        return new GQxQN(n);
    }

    @Override
    public R f(RxR r) {
        Integer x1 = r.x1(), y1 = r.y1();
        Integer x2 = r.x2(), y2 = r.y2();

        if ((x1 <= N) && (y1 <= N) && (x2 <= N) && (y2 <= N)) {
            return r.x().times(r.y());
//            return R.R(x1 * x2, y1 * y2);
        } else {
            return R.R(1, 1);
        }

    }

    @Override
    public Q fmap(QxQ rxr) {
        List<R> LQ = new ArrayList<R>();
        Iterator<RxR> it = rxr.liste().iterator();
        while (it.hasNext()) {
            LQ.add(f(it.next()));
        }
        return new Q(LQ);
    }
}















